<template>
  <page-frame>
    <div class="consultingNewComplaint">
      <div class="toptitle">
        <div class="left">照护等级配置-新增</div>
        <div class="right">
          <div class="btns">
            <div v-if="!ways">
              <el-button @click="back">返回</el-button>
              <el-button @click="submit('ruleForm')" class="lightGreenBtn">保存</el-button>
            </div>
          </div>
        </div>
      </div>
      <div class="borderT"></div>
      <div class="file-content">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="350px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="所属机构:" prop="ruleForm.name">
                <el-input v-model="ruleForm.name" disabled></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-form-item label="子机构是否通用(子机构将同步该照护等级):" prop="isCommon">
              <el-radio class="radio" v-model="ruleForm.isCommon" :label="1">是</el-radio>
              <el-radio class="radio" v-model="ruleForm.isCommon" :label="0">否</el-radio>
            </el-form-item>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="照护等级名称:" prop="lName">
                <el-input v-model="ruleForm.lName" disabled placeholder="请输入照护等级名称" :disabled="ways"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="照护等级描述" prop="lDescription ">
                <el-input v-model="ruleForm.lDescription " disabled placeholder="请输入照护等级描述" :disabled="ways"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        </span>
    </div>
  </page-frame>
</template>

<script>

  import staffApi from '../../service/corporation/staffApi'
  import careLevelApi from '../../service/serManagement/careLevelApi'

  export default {
    data() {
      return {
        currentCateObj:{},
        teams:{
          orgName:""
        },
        ways: false,
        emps: [],
        //提交的表单，上传到后端的数据
        ruleForm: {
          isCommon: 1,//子机构是否通用(0:不通用，1:通用)
          lDescription: "",//照护等级描述
          lName: "",//照护等级名称
          name: "",//机构名称
        },
        //判断照护等级是否填写
        rules: {
//          isCommon: [
//            {required: true, message: '请', trigger: 'change'},
//          ],
          lName: [
            {required: true, message: '请输入照护等级名称', trigger: 'blur'},
          ],
        },
      }
    },
    methods: {
      init() {
        if(this.$route.params.careObj){
          this.currentCateObj = this.$route.params.careObj;
          this.ruleForm.lName = this.currentCateObj.lName;
          this.ruleForm.lDescription = this.currentCateObj.lDescription;
        }else {
          this.$router.push({name: 'careLeaveSeeting'})
        };

       this.getOrgName();
      },
      getOrgName() {
        let self = this;
        staffApi.getLoginPersonInfo().then(
          (response)=>{
            if(response.data.status==200){
              self.ruleForm.name= response.data.data.orgName;
            }else{}
          },
        );
      },

      /**
       * 提交
       */
      submit(ruleForm) {
        this.$refs[ruleForm].validate((valid) => {
          if (valid) {
            careLevelApi.saveCareLevel(this.ruleForm).then(
              (response)=>{
                if(response.data.status==200){
                  this.$message({
                    message:'提交成功',
                    type:'success'
                  });
                  //跳转
                  this.$router.push({name:'careLeaveSeeting'});
                }
              }
            );
          } else {
            return false;
          }
        });
      },
      //返回
      back() {
        this.$router.push({name: 'careLeaveSeeting'})
      },

    },
    mounted: function () {
      this.init();
    },
  }
</script>
<style>
  .consultingNewComplaint .file-content {
    width: 80%;
    margin: 50px auto;
  }

  .consultingNewComplaint .el-textarea {
    width: 91% !important;
  }

  .consultingNewComplaint .el-autocomplete {
    width: 100%;
  }

  .consultingNewComplaint .edit .el-form-item__error {
    margin-top: 100px;
  }
</style>
